/**
 * HibernateUtil.java
 * Aug 19, 2013
 * Copyright: TuanTQSE60604@fpt.edu.vn
 */
package utilities;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

/**
 * @author Tuan
 */
public class HibernateUtil {
    private static ServiceRegistry serviceRegistry;
    private static final SessionFactory sessionFactory;

    static {
        try {
            Configuration configuration = new Configuration();
            configuration.addResource("Admin.hbm.xml").addResource("Image.hbm.xml").addResource("Slider.hbm.xml")
                    .addResource("Customer.hbm.xml").addResource("Vps.hbm.xml").addResource("Host.hbm.xml")
                    .addResource("Category.hbm.xml").addResource("Web.hbm.xml").addResource("OrderDetail.hbm.xml")
                    .configure();
            serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
                    .buildServiceRegistry();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
